package cn.yr.oss.configuration;


import cn.yr.oss.MinioOss;
import cn.yr.oss.OssKit;
import cn.yr.oss.properties.OssMinioProperties;
import cn.yr.oss.properties.OssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Minio配置
 *
 * @author Lang 1102076808@qq.com
 * @date 2021-10-06 11:33
 */

@Configuration
@EnableConfigurationProperties({OssMinioProperties.class, OssProperties.class})
@ConditionalOnProperty(
		prefix = "oss",
		name = "sdk",
		havingValue = "minio"
)
public class OssMinioConfiguration {

	@Autowired
	private OssMinioProperties ossMinioProperties;
	@Autowired
	private OssProperties ossProperties;

	@Bean("minioOss")
	public MinioOss minioOss(){
		return new MinioOss(ossMinioProperties.getAccessKey(),ossMinioProperties.getSecretKey()
				,ossMinioProperties.getBucket(),ossProperties.getDomain());
	}

	@Bean("ossKit")
	public OssKit ossKit(){
		OssKit ossKit = new OssKit();
		ossKit.setOss(minioOss());
		return ossKit;
	}

}
